package cn.juni.controller;

import cn.juni.pojo.Orders;
import cn.juni.pojo.Product;
import cn.juni.service.IOrdersService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author Juni
 * @date 2021/2/24
 */
@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    IOrdersService ordersService;

    @RequestMapping("/findAll")
    public String findAllOrders(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "3") Integer pageSize,
                                Orders orders,
                                Model model){
        System.out.println(orders);
        List<Orders> ordersList = ordersService.findAllOrders(pageNum,pageSize,orders);
        System.out.println(ordersList);
        //将数据封装到PageInfo中
        PageInfo pageInfo = new PageInfo(ordersList);
        model.addAttribute("pageInfo",pageInfo);
        return "orders-list";
    }

    @RequestMapping("/findDetail")
    public String findDetail(String orderId,Model model){
        Orders orders = ordersService.findOrderDetail(orderId);
        model.addAttribute("orders",orders);
        return "order-show";
    }
}
